package exception;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FinallyDemo2 {
    public static void main(String[] args) {
        /*FileOutputStream fos = null;
        try {
            fos =new FileOutputStream("./s/fos.txt");
            fos.write(1);

        } catch (IOException e) {
            System.out.println("出错并处理1");
        } finally {
            try {
                if(fos!=null){
                    fos.close();
                }

            } catch (IOException e) {
                System.out.println("出错并处理2");
            }

        }*/
        /*FileOutputStream fos = null;
        try{
            fos=new FileOutputStream("./fos.txt");
            fos.write(1);
        }catch(IOException e){
            System.out.println("异常已处理");
        }finally{
            try {
                if(fos!=null){
                    fos.close();
                }

            } catch (IOException e) {
                System.out.println("异常处理2");
            }
        }*/

        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("./test.txt");
            fos.write(1);
        } catch (IOException e) {
            System.out.println("异常处理1");
        } finally {
            try {
                if(fos!=null){
                    fos.close();
                }

            } catch (IOException e) {
                System.out.println("异常处理2");
            }
        }
    }
}
